package com.ushine.web.log.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ushine.web.component.http.HttpResponseVO;
import com.ushine.web.component.page.PageRequestQuery;
import com.ushine.web.component.page.PageResultVO;
import com.ushine.web.log.model.Log;
import com.ushine.web.log.service.SystemLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.text.ParseException;
import java.util.List;

/**
 * @Author yangh
 * @Date 2020/4/5 12:21
 * @Description 系统日志控制器
 * @Version 1.0
 **/
@Controller
@RequestMapping("log")
@Api(tags = "日志管理-分页查询")
public class SystemLogController {

    @Resource
    private SystemLogService systemLogService;

    @ResponseBody
    @ApiOperation(value = "分页查询日志")
    @PostMapping("listsByPageInfo")
    public HttpResponseVO<PageResultVO<Log>> listsByPageInfo(@ApiParam(value = "日志对象集合", required = true) @RequestBody PageRequestQuery<Log> pageRequestQuery) throws ParseException {
        Page<Log> systemLogPage = systemLogService.listLogByPageHelper(pageRequestQuery);
        return new HttpResponseVO<PageResultVO<Log>>().ok("查询成功", systemLogPage);
    }

    @ResponseBody
    @ApiOperation(value = "分页查询日志")
    @PostMapping("listsByPage")
    public HttpResponseVO<PageResultVO<Log>> listsPage(@ApiParam(value = "日志对象集合", required = true) @RequestBody PageRequestQuery<Log> pageRequestQuery) throws ParseException {
        Page<Log> systemLogPage = systemLogService.listLogByPage(pageRequestQuery);
        return new HttpResponseVO<PageResultVO<Log>>().ok("查询成功", systemLogPage);
    }

    @ResponseBody
    @ApiOperation(value = "查询所有日志")
    @PostMapping("listAllLogs")
    public HttpResponseVO<List<Log>> listAllLogs() {
        List<Log> logs = systemLogService.listAllLogs();
        return new HttpResponseVO<List<Log>>().ok("查询成功", logs);
    }
}
